﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using PowerBooking.RSE.Poco;
using PowerBooking.RSE.Utility.Helpers;
using PowerBooking.RSE.IRepository;

namespace PowerBooking.RSE.Repository.Contexts
{
    /// <summary>
    /// 餐厅蜘蛛引擎上下文
    /// </summary>
    public class RestaurantSpiderEngineContext : ObjectContext,IUnitOfWork
    {
        private Lazy<ObjectSet<SpiderPoco>> spiders;
        private Lazy<ObjectSet<CityPoco>> cities;
        private Lazy<ObjectSet<FilterPoco>> filters;
        private Lazy<ObjectSet<RestaurantPoco>> restaurants;

        public ObjectSet<SpiderPoco> Spiders { get { return spiders.Value; } }
        public ObjectSet<CityPoco> Cities { get { return cities.Value; } }
        public ObjectSet<FilterPoco> Filters { get { return filters.Value; } }
        public ObjectSet<RestaurantPoco> Restaurants { get { return restaurants.Value; } }

        public RestaurantSpiderEngineContext()
            : base(ConnectionHelper.CreateConnectionString("DefaultConnection"))
        {
            spiders = new Lazy<ObjectSet<SpiderPoco>>(() => CreateObjectSet<SpiderPoco>());
            cities = new Lazy<ObjectSet<CityPoco>>(() => CreateObjectSet<CityPoco>());
            filters = new Lazy<ObjectSet<FilterPoco>>(() => CreateObjectSet<FilterPoco>());
            restaurants = new Lazy<ObjectSet<RestaurantPoco>>(() => CreateObjectSet<RestaurantPoco>());
        }

        public void Save()
        {
            SaveChanges();
        }
    }
}
